package com.cskaoyan.app.controller;

import com.cskaoyan.app.bean.common.BasePageInfo;
import com.cskaoyan.app.bean.common.BaseRespVo;
import com.cskaoyan.app.bean.common.CommonData;
import com.cskaoyan.app.bean.po.MarketTopic;
import com.cskaoyan.app.bean.vo.AdminTopicReadVO;
import com.cskaoyan.app.service.AdminTopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("admin/topic")
public class AdminTopicController {

    @Autowired
    private AdminTopicService adminTopicService;

    @GetMapping("list")
    public Object list(BasePageInfo info, String title, String subtitle) {
        CommonData<MarketTopic> data = adminTopicService.list(info, title, subtitle);
        return BaseRespVo.ok(data);
    }

    @PostMapping("create")
    public Object create(@RequestBody MarketTopic marketTopic) {
        MarketTopic data = adminTopicService.create(marketTopic);
        return BaseRespVo.ok(data);
    }

    @GetMapping("read")
    public Object read(Integer id) {
        AdminTopicReadVO data = adminTopicService.read(id);
        return BaseRespVo.ok(data);
    }

    @PostMapping("update")
    public Object update(@RequestBody MarketTopic marketTopic) {
        MarketTopic data = adminTopicService.update(marketTopic);
        return BaseRespVo.ok(data);
    }

    @PostMapping("delete")
    public Object delete(@RequestBody MarketTopic marketTopic) {
        adminTopicService.delete(marketTopic);
        return BaseRespVo.ok();
    }

    @PostMapping("batch-delete")
    public Object batchDelete(@RequestBody Map<String, Integer[]> map) {
        adminTopicService.batchDelete(map);
        return BaseRespVo.ok();
    }
}
